package com.yzs.exam.listener;

import com.yzs.exam.entity.UserEventLog;
import com.yzs.exam.event.UserEvent;
import com.yzs.exam.service.UserEventLogService;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 用户日志监听 -- 认证成功、注册成功、注销成功事件都会触发这个监听器
 * 向数据库插入一天日志记录
 * @author yzs
 * @create 2021-03-22 13:39
 */
@Component
@AllArgsConstructor
public class UserLogListener implements ApplicationListener<UserEvent> {

    private UserEventLogService userEventLogService;

    @Override
    public void onApplicationEvent(UserEvent userEvent) {
        userEventLogService.insertByFilter(userEvent.getUserEventLog());
    }
}
